//
//  LeftOfMySelf.m
//  HYHoney
//
//  Created by dllo on 16/1/25.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "LeftOfMySelf.h"
#import "RESideMenu.h"
#import "LTView.h"
#import "DKNightVersion.h"

@interface LeftOfMySelf () <UITextFieldDelegate>

@property (nonatomic, retain) UIView *newview;
@property (nonatomic, retain) UIImageView *dlView;
@property (nonatomic, retain) UIImageView *viewzc;
@property (nonatomic, retain) UIImageView *viewzhaohui;

@end

@implementation LeftOfMySelf

- (void)dealloc{

    [_newview release];
    [_dlView release];
    [_viewzc release];
    [_viewzhaohui release];
    [super dealloc];
}



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.navigationItem.title = @"个人中心";
    
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithRed:1 green:1 blue:1 alpha:1], NSForegroundColorAttributeName,  nil]];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"xial"] style:UIBarButtonItemStylePlain target:self action:@selector(presentLeftMenuViewController:)];
    
    
    
//    
//    /** 找回 */
//    self.viewzhaohui = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"zz.jpg"]];
//    self.viewzhaohui.frame = self.view.frame;
//    [self.view addSubview:self.viewzhaohui];
//    [_viewzhaohui release];
//    
//    UITextField *textYX = [[UITextField alloc] initWithFrame:CGRectMake(80, 250, self.view.frame.size.width - 160, 40)];
//    textYX.placeholder = @"请输入邮箱";
//    [self.viewzhaohui addSubview:textYX];
//    textYX.borderStyle = 3;
//    [textYX release];
//    
//    
    
    /** 注册 */
    self.viewzc = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"zz.jpeg"]];
    self.viewzc.frame = self.view.frame;
    [self.view addSubview:self.viewzc];
    [_viewzc release];
    
    self.viewzc.userInteractionEnabled = YES;
    
    
    LTView *viewOfUserzc = [[LTView alloc] initWithFrame:CGRectMake(50, 150, self.view.frame.size.width - 100, 40)];
    viewOfUserzc.labelOfLeft.text = @"用户名";
    viewOfUserzc.textFieldOfRight.placeholder = @"请输入用户名";
    [self.viewzc addSubview:viewOfUserzc];
    [viewOfUserzc release];
    
    
    LTView *viewOfPasszc = [[LTView alloc] initWithFrame:CGRectMake(50, 220, self.view.frame.size.width - 100, 40)];
    viewOfPasszc.labelOfLeft.text = @"密  码";
    viewOfPasszc.textFieldOfRight.placeholder = @"请输入密码";
    [self.viewzc addSubview:viewOfPasszc];
    [viewOfPasszc release];
    
    
    LTView *viewOfqueren = [[LTView alloc] initWithFrame:CGRectMake(50, 290, self.view.frame.size.width - 100, 40)];
    viewOfqueren.labelOfLeft.text = @"确认密码";
    viewOfqueren.textFieldOfRight.placeholder = @"请再次输入密码";
    viewOfqueren.textFieldOfRight.secureTextEntry = YES;
    
    [self.viewzc addSubview:viewOfqueren];
    [viewOfqueren release];
    
    
    LTView *viewOfphone = [[LTView alloc] initWithFrame:CGRectMake(50, 360, self.view.frame.size.width - 100, 40)];
    viewOfphone.labelOfLeft.text = @"手机号";
    viewOfphone.textFieldOfRight.placeholder = @"请输入联系方式";
    [self.viewzc addSubview:viewOfphone];
    [viewOfphone release];
    
    LTView *viewOfmail = [[LTView alloc] initWithFrame:CGRectMake(50, 430, self.view.frame.size.width - 100, 40)];
    viewOfmail.labelOfLeft.text = @"邮箱";
    viewOfmail.textFieldOfRight.placeholder = @"请输入邮箱";
    [self.viewzc addSubview:viewOfmail];
    [viewOfmail release];
    
    
    viewOfUserzc.textFieldOfRight.delegate = self;
    viewOfUserzc.textFieldOfRight.clearButtonMode = UITextFieldViewModeWhileEditing;
    viewOfPasszc.textFieldOfRight.delegate = self;
    viewOfPasszc.textFieldOfRight.secureTextEntry = YES;
    viewOfPasszc.textFieldOfRight.clearButtonMode = UITextFieldViewModeWhileEditing;
    viewOfqueren.textFieldOfRight.delegate = self;
    viewOfqueren.textFieldOfRight.clearButtonMode = UITextFieldViewModeWhileEditing;
    viewOfphone.textFieldOfRight.delegate = self;
    viewOfphone.textFieldOfRight.clearButtonMode = UITextFieldViewModeWhileEditing;
    viewOfmail.textFieldOfRight.delegate = self;
    viewOfmail.textFieldOfRight.clearButtonMode = UITextFieldViewModeWhileEditing;
    
    
    
    /** 登录 */
    self.dlView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"zz.jpeg"]];
    self.dlView.frame = self.view.frame;
    [self.view addSubview:self.dlView];
    [_dlView release];
    
    self.dlView.userInteractionEnabled = YES;
    
    LTView *viewOfUser = [[LTView alloc] initWithFrame:CGRectMake(50, 190, self.view.frame.size.width - 100, 40)];
    
    viewOfUser.labelOfLeft.text = @"用户名";
    viewOfUser.textFieldOfRight.placeholder = @"请输入用户名";
    [self.dlView addSubview:viewOfUser];
    [viewOfUser release];
    
    LTView *viewOfPass = [[LTView alloc] initWithFrame:CGRectMake(50, 280, self.view.frame.size.width - 100, 40)];
    
    viewOfPass.labelOfLeft.text = @"密  码";
    viewOfPass.textFieldOfRight.placeholder = @"请输入密码";
    [self.dlView addSubview:viewOfPass];
    [viewOfPass release];
    
    
    viewOfUser.textFieldOfRight.delegate = self;
    viewOfUser.textFieldOfRight.clearButtonMode = UITextFieldViewModeWhileEditing;
    viewOfPass.textFieldOfRight.delegate = self;
    viewOfPass.textFieldOfRight.clearButtonMode = UITextFieldViewModeWhileEditing;
    viewOfPass.textFieldOfRight.secureTextEntry = YES;
    
    
    
    // 键盘模式
    
    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"ISNIGHT"]) {
        
        viewOfUserzc.textFieldOfRight.keyboardAppearance = UIKeyboardAppearanceDark;
        viewOfPasszc.textFieldOfRight.keyboardAppearance = UIKeyboardAppearanceDark;
        viewOfqueren.textFieldOfRight.keyboardAppearance = UIKeyboardAppearanceDark;
        viewOfphone.textFieldOfRight.keyboardAppearance = UIKeyboardAppearanceDark;
        viewOfmail.textFieldOfRight.keyboardAppearance = UIKeyboardAppearanceDark;
        viewOfUser.textFieldOfRight.keyboardAppearance = UIKeyboardAppearanceDark;
        viewOfPass.textFieldOfRight.keyboardAppearance = UIKeyboardAppearanceDark;
        
    }else {
        
        viewOfUserzc.textFieldOfRight.keyboardAppearance = UIKeyboardAppearanceLight;
        viewOfPasszc.textFieldOfRight.keyboardAppearance = UIKeyboardAppearanceLight;
        viewOfqueren.textFieldOfRight.keyboardAppearance = UIKeyboardAppearanceLight;
        viewOfphone.textFieldOfRight.keyboardAppearance = UIKeyboardAppearanceLight;
        viewOfmail.textFieldOfRight.keyboardAppearance = UIKeyboardAppearanceLight;
        viewOfUser.textFieldOfRight.keyboardAppearance = UIKeyboardAppearanceLight;
         viewOfPass.textFieldOfRight.keyboardAppearance = UIKeyboardAppearanceLight;
    }

    
    
    [self createSegment];
}


// 空白处回收键盘
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    [UIView animateWithDuration:0.2 animations:^{
        
        self.dlView.frame = self.view.frame;
        self.viewzc.frame = self.view.frame;
        
    }];
    
    [self.view endEditing:YES];
}


-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    
    /** 背景向上移动 */
    
    [UIView animateWithDuration:0.3 animations:^{
        self.dlView.frame = CGRectMake(0, -100, self.view.frame.size.width, self.view.frame.size.height);
        self.viewzc.frame = CGRectMake(0, -100, self.view.frame.size.width, self.view.frame.size.height);
    }];
    
    
    
    return YES;
}


-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    
    [UIView animateWithDuration:0.2 animations:^{
        
        self.dlView.frame = self.view.frame;
        self.viewzc.frame = self.view.frame;

    }];
    
    
    /** 回收键盘. */
    [textField resignFirstResponder];
    
    
    return YES;
}


-(void)createSegment{
    
    UISegmentedControl *seg = [[UISegmentedControl alloc] initWithItems:@[@"登录",@"注册"]];
    seg.frame = CGRectMake(70, 85, self.view.frame.size.width - 140, 35);
    [self.view addSubview:seg];
    seg.selectedSegmentIndex = 0;
    [seg release];
    [seg addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
    
}


-(void)segmentAction:(UISegmentedControl *)seg{
    
    switch (seg.selectedSegmentIndex) {
        case 0:
            [self.view insertSubview:self.dlView belowSubview:seg];
            break;
        case 1:
            [self.view insertSubview:self.viewzc belowSubview:seg];
            break;
        default:
            break;
    }
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
